const { getAbstractDataList } = require('./data');
const { KEYWORD } = require('./keyword');
const { requestPMIDListData, requestAbstractFromPMID } = require('./request');
const { getXlsxData, splitChunk } = require('./util');

async function pubmedScript() {
  const idList = await requestPMIDListData(KEYWORD);

  const idChunks = splitChunk(idList, 10);
  console.log('--idChunks--', idChunks);

  for (let i = 0; i < idChunks.length; i++) {
    const promises = idChunks[i].map((item) => requestAbstractFromPMID(item));
    const results = await Promise.all(promises);
    console.log('--results--', results);
  }

  const abstractDataList = getAbstractDataList();
  console.log('--abstractDataList--', abstractDataList, abstractDataList?.length);
  getXlsxData(abstractDataList);
}

module.exports = { pubmedScript };
